package tictactoe.GUI;

import tictactoe.util.Score;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;

public class Stats extends javax.swing.JDialog {
    private Score score;
    private Image crossImage, circleImage;

    private Stats(Frame parent) {
        super(parent, true);
        crossImage = new ImageIcon(getClass().getResource("/cz/xf/tomason/tictactoe/GUI/pic/cross_80px.PNG")).getImage();
        circleImage = new ImageIcon(getClass().getResource("/cz/xf/tomason/tictactoe/GUI/pic/circle_80px.PNG")).getImage();
        crossImage = crossImage.getScaledInstance(20, 20, Image.SCALE_SMOOTH);
        circleImage = circleImage.getScaledInstance(20, 20, Image.SCALE_SMOOTH);
    }

    public Stats(Frame parent, Score score) {
        this(parent);
        this.score = score;
        initComponents();
        initTable();
        repaint();
    }

    //@Override
    /*public void paint(Graphics g) {
        super.paint(g);
        if (crossImage != null && circleImage != null) {
            int x = cross.getLocationOnScreen().x - getLocationOnScreen().x;
            int y = cross.getLocationOnScreen().y - getLocationOnScreen().y;
            g.drawImage(crossImage, x, y, null);
            x = circle.getLocationOnScreen().x - getLocationOnScreen().x;
            y = circle.getLocationOnScreen().y - getLocationOnScreen().y;
            g.drawImage(circleImage, x, y, null);
        } else {
            int x = cross.getLocationOnScreen().x - getLocationOnScreen().x;
            int y = cross.getLocationOnScreen().y - getLocationOnScreen().y;
            g.drawLine(x + 2, y + 2, x + 16, y + 16);
            g.drawLine(x + 2, y + 16, x + 16, y + 2);
            x = circle.getLocationOnScreen().x - getLocationOnScreen().x;
            y = circle.getLocationOnScreen().y - getLocationOnScreen().y;
            g.drawOval(x + 2, y + 2, 16, 16);
        }
    }*/

    private void initTable() {
        if (score != null) {
            crossName.setText(score.getCross().getName());
            circleName.setText(score.getCircle().getName());

            crossScore.setText(Integer.toString(score.getCrossPoints()));
            circleScore.setText(Integer.toString(score.getCirclePoints()));

            turnsCount.setText(Integer.toString(score.getTurnsCount()));
        }
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        content = new javax.swing.JPanel();
        centerPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        crossScore = new javax.swing.JLabel();
        circleScore = new javax.swing.JLabel();
        cross = new javax.swing.JPanel();
        circle = new javax.swing.JPanel();
        crossName = new javax.swing.JLabel();
        circleName = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        turnsCount = new javax.swing.JLabel();
        buttonsPanel = new javax.swing.JPanel();
        ok = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        content.setMaximumSize(new java.awt.Dimension(300, 200));
        content.setMinimumSize(new java.awt.Dimension(300, 200));
        content.setPreferredSize(new java.awt.Dimension(300, 200));
        content.setLayout(new java.awt.BorderLayout());

        jPanel1.setLayout(new java.awt.GridBagLayout());

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("tictactoe/GUI/texts"); // NOI18N
        jLabel3.setText(bundle.getString("score")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(1, 0, 1, 5);
        jPanel1.add(jLabel3, gridBagConstraints);

        crossScore.setText("0");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(1, 0, 1, 0);
        jPanel1.add(crossScore, gridBagConstraints);

        circleScore.setText("0");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(1, 0, 1, 0);
        jPanel1.add(circleScore, gridBagConstraints);

        cross.setMaximumSize(new java.awt.Dimension(20, 20));
        cross.setMinimumSize(new java.awt.Dimension(20, 20));
        cross.setPreferredSize(new java.awt.Dimension(20, 20));

        javax.swing.GroupLayout crossLayout = new javax.swing.GroupLayout(cross);
        cross.setLayout(crossLayout);
        crossLayout.setHorizontalGroup(
            crossLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );
        crossLayout.setVerticalGroup(
            crossLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(5, 40, 0, 40);
        jPanel1.add(cross, gridBagConstraints);

        circle.setMaximumSize(new java.awt.Dimension(20, 20));
        circle.setMinimumSize(new java.awt.Dimension(20, 20));

        javax.swing.GroupLayout circleLayout = new javax.swing.GroupLayout(circle);
        circle.setLayout(circleLayout);
        circleLayout.setHorizontalGroup(
            circleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );
        circleLayout.setVerticalGroup(
            circleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(5, 40, 0, 40);
        jPanel1.add(circle, gridBagConstraints);

        crossName.setText("cross");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
        jPanel1.add(crossName, gridBagConstraints);

        circleName.setText("circle");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
        jPanel1.add(circleName, gridBagConstraints);

        jLabel1.setText(bundle.getString("turns")); // NOI18N

        turnsCount.setText("0");

        javax.swing.GroupLayout centerPanelLayout = new javax.swing.GroupLayout(centerPanel);
        centerPanel.setLayout(centerPanelLayout);
        centerPanelLayout.setHorizontalGroup(
            centerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(centerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(centerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(centerPanelLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(41, 41, 41)
                        .addComponent(turnsCount)))
                .addContainerGap(30, Short.MAX_VALUE))
        );
        centerPanelLayout.setVerticalGroup(
            centerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(centerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(centerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(turnsCount)
                    .addComponent(jLabel1))
                .addContainerGap(64, Short.MAX_VALUE))
        );

        content.add(centerPanel, java.awt.BorderLayout.CENTER);

        buttonsPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        ok.setText(bundle.getString("close")); // NOI18N
        ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okActionPerformed(evt);
            }
        });
        buttonsPanel.add(ok);

        content.add(buttonsPanel, java.awt.BorderLayout.PAGE_END);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(content, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(content, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed
        setVisible(false);
    }//GEN-LAST:event_okActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel buttonsPanel;
    private javax.swing.JPanel centerPanel;
    private javax.swing.JPanel circle;
    private javax.swing.JLabel circleName;
    private javax.swing.JLabel circleScore;
    private javax.swing.JPanel content;
    private javax.swing.JPanel cross;
    private javax.swing.JLabel crossName;
    private javax.swing.JLabel crossScore;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton ok;
    private javax.swing.JLabel turnsCount;
    // End of variables declaration//GEN-END:variables

}
